import { createStore } from 'vuex'
import { ColumnProps, PostProps, testData, testPosts } from './testData'

interface userProps {
    isLogin: boolean;
    name?: string;
    id?: number;
}

export interface GlobalDataProps {
    user: userProps;
    column: ColumnProps[];
    post: PostProps[];
}
const store = createStore<GlobalDataProps>({
    state: {
        user: {
            isLogin: false,
            name: 'Leo'
        },
        column: testData,
        post: testPosts
    },
    mutations: {
        login(state, pay) {
            state.user = pay
        },
        article(state, pay) {
            state.post.push(pay)
        }
    },
    getters: {
        getColumnList: (state) => (id: number) => {
            return state.column.find(c => c.id === id)
        },
        getPostList: (state) => (cid: number) => {
            return state.post.filter(c => c.columnId === cid)
        }
    }
})

export default store
